import { plugin } from "alemon";
import data from '../../model/fantasyData.js';
import {
  __PATH,
  Add_HP,
  Read_player,
  existplayer,
  Read_equipment,
  Write_equipment,
  Write_player,
  Read_bag,
  Write_bag,
  Read_mapevent,
  Read_mapmove,
  Set_battleobject,
  Set_battleplayer,
  Judge_up,
  Add_bag,
  Read_state,
  Write_state,
  Read_battleobject,
  Read_battleplayer,
  Write_battleobject,
  Write_battleplayer,
  Read_thingtype,
  ifmingzhong,
  ifbaoji,
  baoji,
  battle_round,
  battle_add,
  delete_battleplayer,
  delete_battleobject,
  Read_skill,
  Read_proplist,
  Read_monster,
  Run_skilltime,
  Read_skilltime,
  Read_skillmp,


} from '../../model/fantasy.js';
import { basename } from "path/win32";
import { userInfo } from "node:os";


export class UserMove extends plugin {
  constructor() {
    super({
      priority: 600,
      rule: [
                {
                    reg: /^(上|下|左|右).*$/,
                    fnc: 'move'
                }, {
                    reg: /^战斗面板$/,
                    fnc: 'battle_board'
                },{
                    reg: /^设置技能.*$/,
                    fnc: 'config_skill'
                },{
                    reg: /^我的技能$/,
                    fnc: 'my_skill'
                },{
                    reg: /^(普攻|技能1|技能2|技能3|技能4)$/,
                    fnc: 'battle_a'
                },{
                    reg: /^使用.*$/,
                    fnc: 'use'
                },{
                    reg: /^逃跑$/,
                    fnc: 'escape'
                },{
                    reg: /^休息$/,
                    fnc: 'relax'
                },
                
      ],
    });
    
  }

    async move(e){
    e.cmd_msg = e.cmd_msg.replace("/", "");
    let usr_qq = e.user_id;
    //有无存档
    let ifexistplay = await existplayer(usr_qq);
    if (!ifexistplay) {
      return;
    }
    if(await Read_state(usr_qq) == "组队战斗"){
      return;
    }
    let player = await Read_player(usr_qq);
    let state = await Read_state(usr_qq);
    let name = player["位置"];
    let value = player["进度"][name];
      if(value < 100){
        e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n此区域你还无法辨认方位\n请先完成初步探索哦~\nTips:发送[探索周边]进行探索`)
        return;
      }else if(state == "战斗"){
        e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你正在战斗中！\nTips:发送[战斗面板]查看战斗信息`)
        return;
      }
      const nowTime = new Date().getTime(); // 获取当前日期的时间戳
      const restTime = nowTime - player.探索记录;
      const moveTime = nowTime - player.行动记录;
      if(restTime < 360000){
        let minute = Math.floor((360000 - restTime) / 60000);
        let second = Math.floor((360000 - restTime - 60000 * minute) / 1000 + 1);
        e.reply(`【${player.昵称}】\n————————————\n您还在休息中哦~\n距离整装待发还差${minute}分${second}秒`);
        return;
      }
      if(moveTime < 3000){
        let second = Math.floor((3000 - moveTime) / 1000 + 1);
        e.reply(`【${player.昵称}】\n————————————\n您还在休息中哦~\n距离整装待发还差${second}秒`);
        return;
      }
    const direct = e.cmd_msg.charAt(0);
    let step = e.cmd_msg.slice(1);
      if (Number.isInteger(direct)) {
        e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n移动距离请输入正整数哦！`)
        return;
      }
      if(step > player["移速"]){
        e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n以你当前的能力，一次只能移动${player["移速"]}格！`)
        return;
      }
      if(step == ""){
        step = 1;
      }else if(step > 0){
        step = step;
      }else{
        e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n移动距离请输入正整数哦！`)
        return;
      }
      let x = player["坐标x"] 
      let y = player["坐标y"] 
      if(direct == "上"){
        y = y + step;
      }else if(direct == "下"){
        y = y - step;
      }else if(direct == "左"){
        x = x - step;
      }else if(direct == "右"){
        x = x - step;
      }


    //暂时1000边界
    if(x > 1000){
      x = 1000;
    }
    if(y > 1000){
      y = 1000;
    }
    if(x < 0){
      x = 0;
    }
    if(y < 0){
      y = 0;
    }
    let thing = await Read_mapmove(player["位置"]);
    let len = thing.length;
    let i = 0;
      for(i = 0; i < len; i++){
        let x下 = thing[i].x轴.split("-")[0];
        let x上 = thing[i].x轴.split("-")[1];
        let y下 = thing[i].y轴.split("-")[0];
        let y上 = thing[i].y轴.split("-")[1];
          if(x >= x下 && x <= x上 && y >= y下 && y <= y上){
            break;
          }
      }
    let type = thing[i]["类型"];
    let object0 = thing[i]["对象"].split("|");
    let num1 = Math.floor(Math.random() * object0.length);
    let object = object0[num1]; 
    let level = thing[i]["等级"];
    let word = thing[i]["描述"];
    player["坐标x"] = x;
    player["坐标y"] = y;
    e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n${word}`);
      if(type == "遇战"){
        let per = thing[i]["概率"];
        let num2 = Math.floor(Math.random() * 100);
        if(num2 > per){
          player.行动记录 = nowTime;
          await Write_player(usr_qq, player);
          return;
        }
        await Set_battleobject(usr_qq, object, level);
        await Set_battleplayer(usr_qq);
        await Write_state(usr_qq, "战斗");
        let monster = await Read_monster(object);
        let keys = Object.keys(monster["开场白"]);
        let randomKey = keys[Math.floor(Math.random() * keys.length)];
        setTimeout(async function() {
                 e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n${monster["开场白"][randomKey]}\n【敌袭！！！】\n敌方阵容:[${object}]\nTips:发送[战斗面板]查看战斗指令`);
              }, 100);
      }else if(type == "奇遇"){



      }
    player.行动记录 = nowTime;
    await Write_player(usr_qq, player);
    return;
    }

    
    async battle_board(e){
    e.cmd_msg = e.cmd_msg.replace("/", "");
    let usr_qq = e.user_id;
    //有无存档
    let ifexistplay = await existplayer(usr_qq);
    if (!ifexistplay) {
      return;
    }
    if(await Read_state(usr_qq) == "组队战斗"){
      return;
    }
    let player = await Read_player(usr_qq);
    let state = await Read_state(usr_qq);
      if(state !== "战斗"){
        e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你不在战斗中！`)
        return;
      }
    let object = await Read_battleobject(usr_qq);
    let word1 = "";
      if(player["等级"] >= object["等级"]){
        word1 = `\n等级：Lv.${object["等级"]}`;
      }else{
        word1 = `\n等级：[?无法感知?]`
      }
    e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n敌方阵容:[${object["名称"]}]` + word1 + `\n◇发送[普攻]普通攻击\n◇发送[技能+1|2|3|4]技能攻击\n◇发送[战斗使用+道具名]使用道具(制作中)\n◇发送[逃跑]逃离战斗(有惩罚)`)
    return;
    }
    
    async battle_a(e){
    e.cmd_msg = e.cmd_msg.replace("/", "");
    let usr_qq = e.user_id;
    //有无存档
    let ifexistplay = await existplayer(usr_qq);
    if (!ifexistplay) {
      return;
    }
    if(await Read_state(usr_qq) == "组队战斗"){
      return;
    }
    let player = await Read_player(usr_qq);
    let state = await Read_state(usr_qq);
      if(state !== "战斗"){
        e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你不在战斗中！`)
        return;
      }
    let object0 = await Read_battleobject(usr_qq);
    let player0 = await Read_battleplayer(usr_qq);
    if(e.cmd_msg == "普攻"){
      player0["当前技能"] = "普攻";
    }else if(e.cmd_msg.substring(0, 2) == "技能"){
      if(e.cmd_msg.slice(2) == "1" || e.cmd_msg.slice(2) == "2" || e.cmd_msg.slice(2) == "3" || e.cmd_msg.slice(2) == "4"){
        player0["当前技能"] = player["技能"].find((item) => item.快捷 === e.cmd_msg.slice(2)).技能名
        if(player0["当前技能"] == null || player0["当前技能"] == undefined){
        e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你尚未学习该技能哦~\nTips:发送[我的技能]查看技能详情`)
        }
      }else{
        e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你的技能指令格式不正确\nTips:发送[我的技能]查看技能详情`)
        return;
      }
    }
    
    const len = object0["技能"].length;
    const num = Math.floor(len * Math.random());
    if(object0["技能"][num]["时间"] > 0){
      const index = object0["技能"].findIndex(obj => obj["时间"] == 0);
      if(index >= 0){
        object0["当前技能"] = object0["技能"][index]["技能名"];
      }else{
        object0["当前技能"] = "普攻";
      }
      
    }else if(object0["技能"][num]["时间"] == 0){
      object0["当前技能"] = object0["技能"][num]["技能名"];
    }else{
      object0["当前技能"] = "普攻";
    }
    let object1 = await battle_add(object0);
    let player1 = await battle_add(player0);
    let word1 = `===当前[${player0["回合"]}]回合===\n————————————`;
    let word2 = "";
    let word3 = "";
    let word4 = "";
    let change = false;
        //慢速互换
      if(player1["速度"] < object1["速度"]){
        change = !change;
        let exchange1 = player1;
        player1 = object1;
        object1 = exchange1;
        exchange1 = player0;
        player0 = object0;
        object0 = exchange1;
      }
        //上半回合
        if(player1["当前技能"] !== "普攻"){
          let num0 = player1["技能"].findIndex(obj => obj["技能名"] == player1["当前技能"]);
          let mp = await Read_skillmp(player1["当前技能"]);
          if(player1["技能"][num0]["时间"] > 0 || player1["当前魔力"] < mp){
            player1["当前技能"] = "普攻";
          }
        }
        word2 = await battle_round(player1, object1);
        if(player1["当前技能"] !== "普攻"){
          let num0 = player1["技能"].findIndex(obj => obj["技能名"] == player1["当前技能"]);
          let mp = await Read_skillmp(player1["当前技能"]);
          player1["技能"][num0]["时间"] = await Read_skilltime(player1["当前技能"]);
          player1["当前魔力"] -= mp;
        }
        player0["当前生命"] = player1["当前生命"];
        player0["当前魔力"] = player1["当前魔力"];
        object0["当前生命"] = object1["当前生命"];
        object0["当前魔力"] = object1["当前魔力"];
        player0["技能"] = player1["技能"];
        player0["增益"] = player1["增益"];
        object0["技能"] = object1["技能"];
        object0["增益"] = object1["增益"];
          if(player0["当前生命"] <= 0 || object0["当前生命"] <= 0){
            if(change){
              change = !change;
              let exchange0 = player0;
              player0 = object0;
              object0 = exchange0;
            }
            if(object0["当前生命"] <= 0){
              word3 = `\n战斗胜利！`;
              if(object0["经验"] > 0){
                player["经验"] += object0["经验"];
                word3 += `\n★获得经验${object0["经验"]}点★`;
                await Judge_up(usr_qq, e);
              }
              let account = object0["掉落"];
              const account_len = account.length;
              let account_type;
              let ran;
              let i;
              for(i = 0; i < account_len; i++){
                ran = Math.random() * 100;
                if(ran <= account[i]["概率"]){
                  account_type = await Read_thingtype(account[i]["名称"]);
                  await Add_bag(usr_qq, account[i]["名称"], account[i]["数量"]);
                  word3 += `\n★获得${account_type}[${account[i]["名称"]}] * ${account[i]["数量"]}★`;
                }
              }
              let skill = object0["技能"];
              const skill_len = skill.length;
              let ran1;
              for(let j = 0; j < skill_len; j++){
                ran1 = Math.random() * 100;
                if(ran1 <= skill[j]["学习率"]){
                  let index = player["技能"].findIndex(obj => obj["技能名"] === skill[j]["技能名"]);
                  if(index == -1){
                    player["技能"].push({"技能名": skill[j]["技能名"],"熟练度": 0, "熟练经验": 0});
                    word3 += `\n☯习得技能[${skill[j]["技能名"]}]☯`;
                  }else{
                    player["技能"][index]["熟练经验"] += 1;
                    word3 += `\n⬆技能[${skill[j]["技能名"]}]愈加纯熟⬆`;
                    const pows = Math.pow(5, player["技能"][index]["熟练度"] + 1);
                    if(player["技能"][index]["熟练经验"] >= pows){
                      player["技能"][index]["熟练度"] += 1;
                      player["技能"][index]["熟练经验"] = player["技能"][index]["熟练经验"] - pows;
                      word3 += `\n⬆⬆⬆ Skill UP ⬆⬆⬆\n☯技能[${skill[j]["技能名"]}]突破☯`;
                    }
                
                  }
                }
              }
              e.reply(word1 + `\n` + word2);
              setTimeout(function() {
                e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————` + word3);
              }, 100);
            }else if(player0["当前生命"] <= 0){
              e.reply(word1 + `\n` + word2);
              word3 = `【${player.昵称} Lv.${player.等级}】\n————————————\n战斗失败！\n你被撅的奄奄一息~\n此时你的耳边似乎传来一声抱有幽怨的叹息\n飘渺悠长，宛若莅远云端\n你的意识逐渐模糊，失去了对身体的支配……\n————————————\n许久后，你渐渐的苏醒，发觉自己并无大碍\n但仿佛失去了什么重要的东西……`;
              setTimeout(function() {
                e.reply(word3);
              }, 100);
            }
              player["当前生命"] = player1["当前生命"];
              player["当前魔力"] = player1["当前魔力"];
              await Write_player(usr_qq, player);
              await Write_state(usr_qq, "自由");
              await delete_battleplayer(usr_qq);
              await delete_battleobject(usr_qq);
              setTimeout(async function() {
                await Judge_up(usr_qq, e);
              }, 200);
              return;
          }
        //信息互换
        change = !change;
        let exchange2 = player1;
        player1 = object1;
        object1 = exchange2;
        exchange2 = player0;
        player0 = object0;
        object0 = exchange2;
        object1 = await battle_add(object0);
        player1 = await battle_add(player0);
        //下半回合
        if(player1["当前技能"] !== "普攻"){
          let num0 = player1["技能"].findIndex(obj => obj["技能名"] == player1["当前技能"]);
          let mp = await Read_skillmp(player1["当前技能"]);
          if(player1["技能"][num0]["时间"] > 0 || player1["当前魔力"] < mp){
            player1["当前技能"] = "普攻";
          }
        }
        word4 = await battle_round(player1, object1);
        if(player1["当前技能"] !== "普攻"){
          let num0 = player1["技能"].findIndex(obj => obj["技能名"] == player1["当前技能"]);
          let mp = await Read_skillmp(player1["当前技能"]);
          player1["技能"][num0]["时间"] = await Read_skilltime(player1["当前技能"]);
          player1["当前魔力"] -= mp;
        }
        player0["当前生命"] = player1["当前生命"];
        player0["当前魔力"] = player1["当前魔力"];
        object0["当前生命"] = object1["当前生命"];
        object0["当前魔力"] = object1["当前魔力"];
        player0["技能"] = player1["技能"];
        player0["增益"] = player1["增益"];
        object0["技能"] = object1["技能"];
        object0["增益"] = object1["增益"];
        player0["回合"] += 1;
        object0["回合"] += 1;
        player0 = await Run_skilltime(player0, 1);
        object0 = await Run_skilltime(object0, 1);
        if(change){
          change = !change;
          let exchange3 = player1;
          player1 = object1;
          object1 = exchange3;
          exchange3 = player0;
          player0 = object0;
          object0 = exchange3;
        }
        await Run_skilltime(object0,1);
        await Run_skilltime(player0,1);
        await Write_battleobject(usr_qq, object0);
        await Write_battleplayer(usr_qq, player0);  
          if(player0["当前生命"] <= 0 || object0["当前生命"] <= 0){
            if(change){
              change = !change;
              let exchange0 = player0;
              player0 = object0;
              object0 = exchange0;
            }
            if(object0["当前生命"] <= 0){
              word3 = `\n战斗胜利！`;
              if(object0["经验"] > 0){
                player["经验"] += object0["经验"];
                word3 += `\n★获得经验${object0["经验"]}点★`;
              }
              let account = object0["掉落"];
              const account_len = account.length;
              let account_type;
              let ran;
              let i;
              for(i = 0; i < account_len; i++){
                ran = Math.random() * 100;
                if(ran <= account[i]["概率"]){
                  await Add_bag(usr_qq, account[i]["名称"], account[i]["数量"]);
                  account_type = await Read_thingtype(account[i]["名称"]);
                  word3 += `\n★获得${account_type}[${account[i]["名称"]}] * ${account[i]["数量"]}★`;
                }
              }
              let skill = object0["技能"];
              const skill_len = skill.length;
              let ran1;
              for(let j = 0; j < skill_len; j++){
                ran1 = Math.random() * 100;
                if(ran1 <= skill[j]["学习率"]){
                  let index = player["技能"].findIndex(obj => obj["技能名"] === skill[j]["技能名"]);
                  if(index == -1){
                    player["技能"].push({"技能名": skill[j]["技能名"],"熟练度": 0, "熟练经验": 0, "快捷": ""});
                    word3 += `\n☯习得技能[${skill[j]["技能名"]}]☯`;
                  }else{
                    player["技能"][index]["熟练经验"] += 1;
                    word3 += `\n⬆技能[${skill[j]["技能名"]}]愈加纯熟⬆`;
                    const pows = Math.pow(5, player["技能"][index]["熟练度"] + 1);
                    if(player["技能"][index]["熟练经验"] >= pows){
                      player["技能"][index]["熟练度"] += 1;
                      player["技能"][index]["熟练经验"] = player["技能"][index]["熟练经验"] - pows;
                      word3 += `\n⬆⬆⬆ Skill UP ⬆⬆⬆\n☯技能[${skill[j]["技能名"]}]突破☯`;
                    }
                
                  }
                }
              }
              e.reply(word1 + `\n` + word2 + `\n————————————\n` + word4)
              setTimeout(function() {
                e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————` + word3);
              }, 100);   
            }else if(player0["当前生命"] <= 0){
              e.reply(word1 + `\n` + word2 + `\n————————————\n` + word4);
              word3 = `【${player.昵称} Lv.${player.等级}】\n————————————\n战斗失败！\n你被撅的奄奄一息~\n此时你的耳边似乎传来一声抱有幽怨的叹息\n飘渺悠长，宛若远莅云端\n你的意识逐渐模糊，失去了对身体的支配……\n————————————\n许久后，你渐渐的苏醒，发觉自己并无大碍\n但仿佛失去了什么重要的东西……`;
              setTimeout(function() {
                e.reply(word3);
              }, 100);
            }
              player["当前生命"] = player1["当前生命"];
              player["当前魔力"] = player1["当前魔力"];
              await Write_player(usr_qq, player);
              await Write_state(usr_qq, "自由");
              await delete_battleplayer(usr_qq);
              await delete_battleobject(usr_qq);
              setTimeout(async function() {
                await Judge_up(usr_qq, e);
              }, 200);
              return;
          }
        e.reply(word1 + `\n` + word2 + `\n————————————\n` + word4);
        return;

    }



//设置技能
async config_skill(e){
    e.cmd_msg = e.cmd_msg.replace("/", "");
    let usr_qq = e.user_id;
    //有无存档
    let ifexistplay = await existplayer(usr_qq);
    if (!ifexistplay) {
      return;
    }
    if(await Read_state(usr_qq) == "组队战斗"){
      return;
    }
    let player = await Read_player(usr_qq);
    let str = e.cmd_msg.slice(4);
    let regex = /\b\d+/;
    let num0 = str.match(regex);
    let skill_num = num0[0];
    if(skill_num !== "1" && skill_num !== "2" && skill_num !== "3" && skill_num !== "4"){
      e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n快捷数字不在要求内哦~\n请为1~4内整数`)
      return;
    }

    let skill_name = str.replace(regex, "");
    let num = player["技能"].findIndex(obj => obj["技能名"] === skill_name);
    if(num >= 0 && num <= 3){
      player["技能"][num]["快捷"] = skill_num;
      await Write_player(usr_qq, player);
      e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n设置[技能${skill_num}]【${skill_name}】成功~`)
      return;
    }else{
      e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你还不会该技能啦！！！`)
      return;
    }    
}

async my_skill(e){
    e.cmd_msg = e.cmd_msg.replace("/", "");
    let usr_qq = e.user_id;
    //有无存档
    let ifexistplay = await existplayer(usr_qq);
    if (!ifexistplay) {
      return;
    }
    let player = await Read_player(usr_qq);
    let skill = player["技能"];
    let len = skill.length;
    let word = `===[${player["昵称"]}]的技能===`;
    let word1 = "";
    let list = {0: "✲初窥门径✲", 1: "✿小有所成✿", 2: "☆登堂入室☆", 3: "★炉火纯青★", 4: "♛登峰造极♛", 5: "☯出神入化☯"};
    let word2 = `\nTips:发送[技能信息+技能名]查看技能信息`;
    for(let i = 0; i < len; i++){
      const name = skill[i]["技能名"];
      const level = skill[i]["熟练度"];
      const level_word = list[level];
      const exp = skill[i]["熟练经验"];
      let key = skill[i]["快捷"];
      if(key !== 1 && key !== 2 && key !== 3 && key !== 4){
        key = ""
      }else{
        key = `\n已设置指令[${key}]`
      }
      word1 += `\n————————————\n【${name}】(${exp}/${Math.pow(5, level + 1)})\n${level_word}${key}`;
    }
    if(word1 == ""){
      word1 = `\n————————————\n[你尚未学习任何技能]`;
    }
    e.reply(word + word1 + word2);
    return;

}

async use(e){
    e.cmd_msg = e.cmd_msg.replace("/", "");
    let usr_qq = e.user_id;
    //有无存档
    let ifexistplay = await existplayer(usr_qq);
    if (!ifexistplay) {
      return;
    }
    if(await Read_state(usr_qq) == "组队战斗"){
      return;
    }
    let player = await Read_player(usr_qq);
    let state = await Read_state(usr_qq);
    if(state == "战斗"){
      e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你正在战斗中！`)
    }
    const thing_name0 = e.cmd_msg.replace("使用", "");
    let thing_name;
    let number;
    if(thing_name0.includes("*")){
      thing_name = thing_name0.split("*")[0];
      number = Number(thing_name0.split("*")[1]);
    }else{
      thing_name = thing_name0;
      number = 1;
    }
    const type = await Read_thingtype(thing_name);
    if(type == false){
      e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n[${thing_name}]不存在于这方世界~`);
      return;
    }
    let bag = await Read_bag(usr_qq);
    let bag_thing = bag[type].find(obj => obj["名称"] == thing_name);
    if(bag_thing == undefined){
      e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你未拥有[${thing_name}]`);
      return;
    }
    const numb = bag_thing["数量"];
    if(numb < number){
      e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你没有足够的[${thing_name}]`);
      return;
    }
    //使用道具
    if(type == "道具"){
      let list = await Read_proplist(usr_qq);
      let numb = list.findIndex(obj => obj["名称"] == thing_name);
      const typein = list[numb]["类别"];
      const func = list[numb]["功能"];
      const num = list[numb]["数值"];
      //如果是消耗品
      if(typein == "消耗品"){
        const hp1 = player["当前生命"];
        const mp1 = player["当前魔力"];

        //消耗品为生命回复
        if(func == "生命回复"){
          const num1 = Number(num.split("+")[0]);
          const num2 = Number(num.split("+")[1]);
          for(let i = 0; i < number; i++){
            player["当前生命"] += player["生命上限"] * num1 / 100;
            player["当前生命"] += num2;
            if(player["当前生命"] > player["生命上限"]){
              player["当前生命"] = player["生命上限"];
            }
          }
          e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n使用[${thing_name}] * ${number}成功！\n[${player.昵称}]生命：${hp1}→${player["当前生命"]}`)

        //消耗品为魔力回复
        }else if(func == "魔力回复"){
          const num1 = Number(num.split("+")[0]);
          const num2 = Number(num.split("+")[1]);
          for(let i = 0; i < number; i++){
            player["当前魔力"] += player["魔力上限"] * num1 / 100;
            player["当前魔力"] += num2;
            if(player["当前魔力"] > player["魔力上限"]){
              player["当前魔力"] = player["魔力上限"];
            }
          }
          e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n使用[${thing_name}] * ${number}成功！\n[${player.昵称}]魔力：${mp1}→${player["当前魔力"]}`)

        //消耗品为生命魔力回复
        }else if(func == "生命魔力回复"){
          const num1 = Number(num.split("+")[0]);
          const num2 = Number(num.split("+")[1]);
          for(let i = 0; i < number; i++){
            player["当前魔力"] += player["魔力上限"] * num1 / 100;
            player["当前魔力"] += num2;
            player["当前生命"] += player["生命上限"] * num1 / 100;
            player["当前生命"] += num2;
            if(player["当前魔力"] > player["魔力上限"]){
              player["当前魔力"] = player["魔力上限"];
            }
            if(player["当前生命"] > player["生命上限"]){
              player["当前生命"] = player["生命上限"];
            }
          }
          e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n使用[${thing_name}] * ${number}成功！\n[${player.昵称}]生命：${hp1}→${player["当前生命"]}\n[${player.昵称}]魔力：${mp1}→${player["当前魔力"]}`)
        }
        await Add_bag(usr_qq, thing_name, -number);
        await Write_player(usr_qq, player);
        return;
      }
    }
    return;
    }

    async escape(e){
    e.cmd_msg = e.cmd_msg.replace("/", "");
    let usr_qq = e.user_id;
    //有无存档
    let ifexistplay = await existplayer(usr_qq);
    if (!ifexistplay) {
      return;
    }
    if(await Read_state(usr_qq) == "组队战斗"){
      return;
    }
    let player = await Read_player(usr_qq);
    let state = await Read_state(usr_qq);
      if(state !== "战斗"){
        e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你不在战斗中！`)
        return;
      }
    let object0 = await Read_battleobject(usr_qq);
    const exp = object0["经验"] * 2;
    player["经验"] -= exp;
    await Write_player(usr_qq, player);
    await Write_state(usr_qq, "自由");
    await delete_battleplayer(usr_qq);
    await delete_battleobject(usr_qq);
    e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你狼狈的逃跑了\n✘损失了${exp} 点经验✘`);
    return;
    }

    async relax(e){
    e.cmd_msg = e.cmd_msg.replace("/", "");
    let usr_qq = e.user_id;
    //有无存档
    let ifexistplay = await existplayer(usr_qq);
    if (!ifexistplay) {
      return;
    }
    if(await Read_state(usr_qq) == "组队战斗"){
      return;
    }
    let player = await Read_player(usr_qq);
    const nowTime = new Date().getTime() // 获取当前日期的时间戳
    const restTime = nowTime - player.探索记录
    if(restTime < 360000){
       let minute = Math.floor((360000 - restTime) / 60000);
       let second = Math.floor((360000 - restTime - 60000 * minute) / 1000 + 1)
    e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n您还在休息中哦~\n距离整装待发还差${minute}分${second}秒`)
    return;
    }
    player["当前生命"] = player["生命上限"];
    player["当前魔力"] = player["魔力上限"];
    player["探索记录"] = nowTime;
    await Write_player(usr_qq, player);
    e.reply(`【${player.昵称} Lv.${player.等级}】\n————————————\n你找了个安全的地方，缓缓陷入了沉睡`);
    return;
    }








}